/* eslint-disable */
/**表单各模块的配置
   表单各模块的配置，配置名称建议与模块目录名保持一致。
   自动合计：列表字段包含(qty、amount)时，将自动进行合计
   列表宽度计算：根据数据视图字段属性，以及所选择打印机纸张属性
 使用示例:
 入参：
   viewForm:      编辑界面的根对象
   viewForm 说明：
   viewForm.form					编辑界面data.form
   viewForm.$refs.childDataView	编辑界面dataview对象实例，与dataview属性ref一致
 出参：
     setId  		【必须】，用来标记locationstorage，建议使用配置方法名
     dvParam		【必须】，数据网格查询参数，没特殊要求，可直接使用 getDvParam
     form		【必须】，表单区域data.form对象
     title		【非必须】，打印标题
     codeLeft	【非必须】，左上图形码，支持二维码和条形码，模块单号条形码
     codeRight	【非必须】，右上图形码，支持二维码和条形码，模块关联单号条形码(如果有)或者模块单号二维码
     head		【非必须】，打印表头
     foot		【非必须】，打印表尾
 *
 */
const printSet = {
 //数据网格参数
  getDvParam(dataView){
    let param = {
      //后台查询接口，若最后一个路径包含page，则替换成list
      listEntry: dataView.listEntry,
      //当前对象字段列表
      columns: dataView.columns,
      //排序条件
      orderString: dataView.generateOrder(),
      //当前对象数据总计
      totalResult: dataView.tablePage.totalResult,
      //是否打印序号列
      noPrintSeq: dataView.noPrintSeq != undefined ? dataView.noPrintSeq : false
    }
    param.queryString = dataView.generateQuery(false, {orderString: param.orderString })
    return param
  },
  //获取数据网格的所有数据
  async getDvAllData(dataView){
    const params = {
      queryString: dataView.generateQuery(),
      orderString: dataView.generateOrder()
    }
    let listEntry = dataView.listEntry.indexOf('page')==-1? dataView.listEntry: dataView.listEntry.substring(0,dataView.listEntry.lastIndexOf('page'))+'list'
    let allData = []
    await global.$ajax.get(listEntry, { params }).then((response) => {
      if (response.code == 0) {
        allData = response.data
      }
    })
    console.log('getDvAllData.allData',allData)
    return allData
  },
  async getPrintParams(viewForm, busKey, childDaraView) {
    let childDataView = childDaraView || 'childDataView'
    let printTemplate = {
      setId: busKey,
      dvParam: this.getDvParam(viewForm[childDataView] || viewForm.$refs[childDataView]),
      form: viewForm.form,
      fromConfig: true,
      usePrintSet: true
    }
    let templateId = 0
    await global.$ajax.get(`/print/template/getByBusKey/${busKey}`).then((resp) => {
      let configJson = JSON.parse(resp.data.configJson)
      templateId = resp.data.id
      Object.keys(configJson).forEach((key) => {
        if (Object.prototype.hasOwnProperty.call(configJson, key)) {
          printTemplate[key] = configJson[key]
        }
      })
    })

    if (templateId == 0) {
      viewForm.$message.warning('打印设置错误，不能进行打印')
      return
    }

    await global.$ajax.get(`/print/field/getByTemplate/${templateId}`).then((resp) => {
      //barCodes
      let barcodes = resp.data.filter(data => data.type == 1)
      if (barcodes.length > 0) {
        printTemplate['barcodes'] = barcodes.sort((p1, p2) => p1.sort - p2.sort).map(data => {
          return {
            name: data.field,
            text: data.label,
            col: data.width,
            type: data.format,
            flagShareRow: data.flagShareRow,
            shareRow: data.shareRow,
            alignType: data.alignType
          }
        })
      }

      //Header
      let headers = resp.data.filter(data => data.type == 2)
      if (headers.length > 0) {
        printTemplate['head'] = headers.sort((p1, p2) => p1.sort - p2.sort).map(data => {
          return {
            name: data.field,
            text: data.label,
            col: data.width,
            dateFmt: data.format,
            dict: data.dict,
            fontSize: data.fontSize,
            expression: data.expression,
            flagFontBold: data.flagFontBold,
            flagLineFeed: data.flagLineFeed,
            formation: data.formation,
            flagShareRow: data.flagShareRow,
            shareRow: data.shareRow,
            alignType: data.alignType
          }
        })
      }
      //Items
      let items = resp.data.filter(data => data.type == 3)
      if (items.length > 0) {
        printTemplate['dvParam']['columns'] = items.sort((p1, p2) => p1.sort - p2.sort).map(data => {
          return {
            hidden: false,
            name: data.field,
            title: data.label,
            width: data.width,
            sort: data.sort,
            dict: data.dict,
            fontSize: data.fontSize,
            dateFmt: data.format,
            expression: data.expression,
            flagFontBold: data.flagFontBold,
            flagLineFeed: data.flagLineFeed,
            flagShowNegative: data.flagShowNegative,
            alignType: data.alignType
          }
        })
        printTemplate['sumFields'] = items.filter(data => data.summary).map(data => data.field)
        printTemplate['groupFields'] = items.filter(data => data.flagGroup).map(data => data.field)
        printTemplate['pagebreakFields'] = items.filter(data => data.flagBreak).map(data => data.field)


        let orderItems = items.filter(item => global.strings.isNotEmpty(item.orderRule))
        if (orderItems != null && orderItems.length > 0) {
          let wrapper = global.$newWrapper()
          orderItems.forEach(item => {
            wrapper.orderConditions.push({ field: item.field, rule: item.orderRule })
          })
          printTemplate.dvParam.orderString = JSON.stringify(wrapper.orderConditions)
        }
      }

      //Footer
      let footers = resp.data.filter(data => data.type == 4)
      if (footers.length > 0) {
        printTemplate['foot'] = footers.sort((p1, p2) => p1.sort - p2.sort).map((data, index) => {
          return {
            name: data.field == null ? '' + index : data.field,
            text: data.label,
            col: data.width,
            dateFmt: data.format,
            dict: data.dict,
            fontSize: data.fontSize,
            expression: data.expression,
            flagFontBold: data.flagFontBold,
            flagLineFeed: data.flagLineFeed
          }
        })
      }
    })
    return printTemplate
  },
  //手动入库
  inOrderManual (viewForm){
    return {
      setId:'inOrderManual',
      dvParam: this.getDvParam(viewForm.$refs.childDataView),
      form: viewForm.form,
      title: '验收入库单',
      codeLeft: {name: 'busKey', text: '入库单号',type: 'barcode'},
      codeRight: {name: 'busKey', text: '入库单号',type: 'qrcode'},
      head: [
        {name: 'supplierName', text: '供应商',col: 16},
        {name: 'warehouseName', text: '入库仓库',col: 8},
        {name: 'busDate', text: '入库日期',dateFmt: 'yyyy-MM-dd'},
        {name: 'busKey', text: '入库单号'},
        {name: 'amount', text: '金额'}
      ],
      foot: [
        {name: '1', text: '制单人', col: 8,value: viewForm.utils.getCurrentUser().name},
        {name: '2',text: '保管人', col: 8},
      ]
    }
  },

  //供应商入库
  inOrder (viewForm){
    let param = this.inOrderManual(viewForm)
    param.setId = 'inOrder'
    param.title = '验收入库单'
    param.codeLeft = {name: 'busKey', text: '入库单号',type: 'barcode'}
    param.codeRight = {name: 'asnKey', text: '送货单',type: 'barcode'}
    return param
  },
  //科室请领
  apply (viewForm){
    return {
      setId:'apply',
      dvParam: this.getDvParam(viewForm.$refs.childDataView),
      form: viewForm.form,
      title: '科室请领单',
      codeLeft: {name: 'busKey', text: '请领单号',type: 'barcode'},
      head: [
        {name: 'busDate', text: '请领日期',dateFmt: 'yyyy-MM-dd',col: 8},
        {name: 'deptName', text: '请领科室',col: 8},
        {name: 'amount', text: '金额',col: 8},
        {name: 'busUser', text: '请领人'},
        {name: 'remark', text: '备注'}
      ],
      foot: [
        {name: '1', text: '主管', col: 8},
        {name: '2',text: '经手人', col: 8},
        {name: '3',text: '签收', col: 8},
      ]
    }
  },
  //科室需求
  demand (viewForm){
    return {
      setId:'demand',
      dvParam: this.getDvParam(viewForm.$refs.childDataView),
      form: viewForm.form,
      title: '科室需求单',
      codeLeft: {name: 'busKey', text: '需求单号',type: 'barcode'},
      head: [
        {name: 'busDate', text: '需求日期',dateFmt: 'yyyy-MM-dd',col: 8},
        {name: 'deptName', text: '需求科室',col: 8},
        {name: 'amount', text: '金额',col: 8},
        {name: 'busUser', text: '制单人'},
        {name: 'remark', text: '备注'}
      ],
      foot: [
        {name: '1', text: '主管', col: 8},
        {name: '2',text: '经手人', col: 8},
        {name: '3',text: '签收', col: 8},
      ]
    }
  },
  //科室配送
  dist (viewForm){
    return {
      setId:'dist',
      dvParam: this.getDvParam(viewForm.$refs.childDataViewPick),
      form: viewForm.form,
      title: global.settings.hospitalName + '科室出库单',
      codeLeft: {name: 'busKey', text: '配送单号',type: 'barcode'},
      head: [
        {name: 'warehouseName', text: '配送仓库',col: 8},
        {name: 'busDate', text: '配送日期',dateFmt: 'yyyy-MM-dd',col: 8},
        {name: 'deptName', text: '配送至',col: 8},
        {name: 'remark', text: '备注', col: 16},
        {name: 'amount', text: '整单金额',col: 8},
      ],
      foot: [
        {name: '1', text: '制单人', col: 8,value: viewForm.utils.getCurrentUser().name},
        {name: 'picker',text: '拣货人', col: 8},
        {name: '2',text: '配送人', col: 8},
        {name: '3',text: '领用人', col: 8},
      ]
    }
  },
  //科室退货
  deptReturn (viewForm){
    let dvParam = this.getDvParam(viewForm.$refs.childDataView)
    let wrapper = global.$newWrapper()
    wrapper.orderConditions.push({ field: 'matrName', rule: 'asc' })
    dvParam.orderString = JSON.stringify(wrapper.orderConditions)
    return {
      setId:'deptReturn',
      dvParam: dvParam,
      form: viewForm.form,
      title: '科室退货单',
      codeLeft: {name: 'busKey', text: '退货单号',type: 'barcode'},
      head: [
        {name: 'busDate', text: '退货日期',dateFmt: 'yyyy-MM-dd',col: 8},
        {name: 'deptName', text: '退货科室',col: 16},
        {name: 'amount', text: '金额',col: 8},
        {name: 'remark', text: '备注', col: 16},
      ],
      foot: [
        {name: '1', text: '库管', col: 6},
        {name: '2',text: '科室', col: 6},
        {name: '3',text: '退货人', col: 6},
      ]
    }
  },
  //供应商出库
  outOrder (viewForm){
    return {
      setId:'outOrder',
      dvParam: this.getDvParam(viewForm.$refs.childDataView),
      form: viewForm.form,
      title: global.settings.hospitalName+'供应商出库单-汇总',
      codeLeft: {name: 'busKey', text: '退货单号',type: 'barcode'},
      head: [
        {name: 'busKey', text: '出库单号',col: 8},
        {name: 'warehouseName', text: '出库仓库',col: 8},
        {name: 'busDate', text: '出库日期',dateFmt: 'yyyy-MM-dd',col: 8},
        {name: 'supplierName', text: '供应商',col: 16},
        {name: 'amount', text: '整单金额',col: 8,labelStyle: {fontSize: '14px'},valueStyle: {fontSize: '14px'}},
        {name: 'remark', text: '备注', col: 24},
      ],
      foot: [
        {name: '1', text: '制单人', col: 6},
        {name: '2',text: '退货人', col: 6},
        {name: '3',text: '供应商', col: 6},
      ]
    }
  },
  //病人消耗
  oprtUse (viewForm){
    return {
      setId:'oprtUse',
      dvParam: this.getDvParam(viewForm.$refs.childDataView),
      form: viewForm.form,
      title: '病人消耗单',
      codeLeft: {name: 'busKey', text: '病人消耗单',type: 'barcode'},
      head: [
        {name: 'deptName', text: '开立科室',col: 8},
        {name: 'execDeptName', text: '执行科室',col: 8},
        {name: 'busDate', text: '记账日期',dateFmt: 'yyyy-MM-dd',col: 8},
        {name: 'inpatientNo', text: '住院号',col: 8},
        {name: 'patientName', text: '患者',col: 8},
        {name: 'busDate', text: '手术日期',dateFmt: 'yyyy-MM-dd',col: 8},
        {name: 'amount', text: '金额',col: 8},
      ],
      foot: [
        {name: '1', text: '记账人', col: 6},
        {name: '2',text: '科室', col: 6},
        {name: '3',text: '库房审核人', col: 6},
      ]
    }
  },
  printMerge (viewForm){
    return {
      setId:'printMerge',
      dvParam: this.getDvParam(viewForm.$refs.childDataView),
      form: viewForm.form,
      title: '病人消耗合单',
      codeLeft: {name: 'busKey', text: '病人消耗单',type: 'barcode'},
      //分单字段列表
      pagebreakFields: ['flagInit'],

      //将分单字段显示到副标题
      pagebreakFieldAppendTitle:false,

      //分组字段列表，如果分单了，则必须包含分单字段
      groupFields: ['flagInit','matrId','matrSpec','packageUnit','lot', 'expDate','rfid'],
      //隐藏字段
      hideFields: ['packageQty'],

      //合计字段
      sumFields: ['skuQty','amount'],
      head: [

        {name: 'busKey', text: '合单编号',col: 8},
        {name: 'inpatientNo', text: '住院号',col: 8},
        {name: 'patientName', text: '患者',col: 8},
        {name: 'deptName', text: '开单科室',col: 8},
        {name: 'busDate', text: '合单日期',dateFmt: 'yyyy-MM-dd',col: 8},
        {name: 'amount', text: '金额',col: 8},
        {name: 'remark', text: '备注',col: 8},
      ],
      foot: [
        {name: '1', text: '科室', col: 6},
        {name: '2',text: '库房审核人', col: 6},
        {name: '3',text: '设备科', col: 6},
      ]
    }
  },
  //科室消耗
  deptUse (viewForm){
    return {
      setId:'deptUse',
      dvParam: this.getDvParam(viewForm.$refs.childDataView),
      form: viewForm.form,
      title: global.settings.hospitalName +'-科室消耗单',
      codeLeft: {name: 'useKey', text: '消耗单号',type: 'barcode'},
      head: [
        {name: 'useKey', text: '单号',col: 6},
        {name: 'useDate', text: '消耗日期',dateFmt: 'yyyy-MM-dd',col: 6},
        {name: 'deptName', text: '来源科室',col: 12},
        {name: 'amount', text: '整单金额',col: 6},
        {name: 'warehouseName', text: '消耗仓库',col: 12},

      ],
      foot: [
        {name: '1', text: '设备科审核', col: 6},
        {name: '2',text: '库管', col: 6},
        {name: '3',text: '科室负责人', col: 6},
      ]
    }
  },
  //科室消耗合并汇总
  useMerageSum (viewForm){
    return {
      setId:'useMerageSum',
      dvParam: this.getDvParam(viewForm.$refs.childDataView),
      form: viewForm.form,
      tableName: 'dept_use',
      pkName: 'id',
      pkValue: viewForm.form.id,
      title: global.settings.hospitalName+'-科室消耗单',
      codeLeft: {name: 'busKey', text: '消耗单号',type: 'barcode'},
      //分单字段列表
      pagebreakFields: ['flagInit'],
      //分组字段列表，如果分单了，则必须包含分单字段
      groupFields: ['flagInit','matrId','matrSpec','lot', 'expDate'],
      //隐藏字段
      hideFields: ['snNo','rfid'],

      //合计字段
      sumFields: ['skuQty','amount'],
      head: [
        {name: 'useKey', text: '单号',col: 6},
        {name: 'useDate', text: '消耗日期',dateFmt: 'yyyy-MM-dd',col: 6},
        {name: 'deptName', text: '来源科室',col: 12},
        {name: 'amount', text: '整单金额',col: 6},
        {name: 'warehouseName', text: '消耗仓库',col: 12},
      ],
      foot: [
        {name: '1', text: '设备科审核', col: 6},
        {name: '2',text: '库管', col: 6},
        {name: '3',text: '科室负责人', col: 6},
      ]
    }
  },
  //科室消耗合并明细
  useMerage (viewForm){
    return {
      setId:'useMerage',
      dvParam: this.getDvParam(viewForm.$refs.childDataView),
      form: viewForm.form,
      title: '科室消耗单',
      codeLeft: {name: 'busKey', text: '消耗单号',type: 'barcode'},
      head: [
        {name: 'deptName', text: '来源科室',col: 8},
        {name: 'deptName', text: '消耗库存地',col: 8},
        {name: 'busDate', text: '记账日期',dateFmt: 'yyyy-MM-dd',col: 8},
        {name: 'amount', text: '金额',col: 8},
      ],
      foot: [
        {name: '1', text: '设备科审核', col: 6},
        {name: '2',text: '库管', col: 6},
        {name: '3',text: '科室负责人', col: 6},
      ]
    }
  },
  //科室消耗
  oprtDist (viewForm){
    return {
      setId:'oprtDist',
      dvParam: this.getDvParam(viewForm.$refs.childDataView),
      form: viewForm.form,
      title: '手术间备货配送单',
      codeLeft: {name: 'oprtApplyKey', text: '备货单号',type: 'barcode'},
      head: [
        {name: 'deptName', text: '申请科室',col: 8},
        {name: 'warehouseNameFrom', text: '申请手术间',col: 8},
        {name: 'oprtApplyDate', text: '请领日期',dateFmt: 'yyyy-MM-dd',col: 8},
      ],
      foot: [
        {name: '1', text: '设备科审核', col: 6},
        {name: '2',text: '库管', col: 6},
        {name: '3',text: '科室负责人', col: 6},
      ]
    }
  },

  //期初入库
  inOrderInit (viewForm){
    return {
      setId:'inOrderInit',
      dvParam: this.getDvParam(viewForm.$refs.childDataView),
      form: viewForm.form,
      title: '期初入库单',
      codeLeft: {name: 'busKey', text: '入库单号',type: 'barcode'},
      codeRight: {name: 'busKey', text: '入库单号',type: 'qrcode'},
      head: [
        {name: 'supplierName', text: '供应商',col: 16},
        {name: 'warehouseName', text: '入库仓库',col: 8},
        {name: 'busDate', text: '入库日期',dateFmt: 'yyyy-MM-dd'},
        {name: 'busKey', text: '入库单号'},
        {name: 'amount', text: '金额'}
      ]
    }
  },
  //科室配送  分单汇总打印(按拼命品规批次效期)
  distPrintSum (that, button){
    let dvParam =  this.getDvParam(that.$refs.childDataViewPick)
    let wrapper = global.$newWrapper()
    wrapper.orderConditions.push({ field: 'matrName', rule: 'asc' })
    dvParam.orderString = JSON.stringify(wrapper.orderConditions)

    //使用列配置
    if (button.printColumns && button.printColumns.length > 0) dvParam.columns = button.printColumns


    let tdLabelStyle = ' style="width: 60px;display: inline-block;" '
    let outerHTML =$(that.$refs.distKey.$el).clone()
    outerHTML.show()
    return {
      setId:'distPrintSum',
      printerPageWidth: button.printerPageWidth,
      printerPageHeight: button.printerPageHeight,
      printerPageSize: button.printerPageSize,
      //使用列配置
      usePrintSet: true,
      dvParam: dvParam,
      form: that.form,

      tableName: 'wm_dist',
      pkName: 'id',
      pkValue: that.form.id,

      //分组字段列表，如果分单了，则必须包含分单字段
      groupFields: ['matrId','matrSpec','lot', 'expDate','packageUnit'],

      //合计字段
      sumFields: ['packageQty','amount', 'skuQty'],
      headHtml: `
<table style="border-collapse: collapse; width: 99%; margin-right: auto; table-layout: fixed; ">
    <tr>
        <td  colspan="2">
          <table style="border-collapse: collapse; width: 99%; margin-right: auto;  ">
              <tr>
                  <td colspan="2" style="font-size: 16px;font-weight: bold;padding-bottom: 5px;text-align: center">${global.settings.hospitalName+that.form.warehouseName+'送货单'}</td>
              </tr>
              <tr >
                  <td style="font-size: 12px;text-align: left"><span ${tdLabelStyle}>领用科室：</span>${that.form.deptName}</td>
                   <td style="font-size: 12px;text-align: left"><span  ${tdLabelStyle}>配送仓库：</span>${that.form.warehouseName}</td>
              </tr>
               <tr>
                  <td style="font-size: 12px;text-align: left"><span  ${tdLabelStyle}>申领人：</span>${that.form.applyUser}</td>
                   <td style="font-size: 12px;text-align: left"><span  ${tdLabelStyle}>备注：</span>${that.form.remark}</td>
              </tr>
               <tr>
                  <td style="font-size: 12px;text-align: left"><span  ${tdLabelStyle}>制单时间：</span>${that.form.busDate}</td>
                   <td style="font-size: 12px;text-align: left"><span  ${tdLabelStyle}>出库日期：</span>${global.dates.formatToAnotherPattern(that.form.busDate,'yyyy-MM-dd')}</td>
              </tr>
          </table>
        </td>
        <td>
            ${outerHTML.prop("outerHTML")}
        </td>
    </tr>
</table>
      `,
      footHtml: `
<table style="border-collapse: collapse; width: 99%; margin-right: auto; table-layout: fixed; ">
    <tr>
        <td colspan="3" style="font-size: 12px;text-align: left">第一联财务，第二联仓库，第三联存根联，第四联科室。</td>
        <td colspan="2" style="font-size: 12px;text-align: left">
        收货地址：${global.strings.defaultIfBlank(that.form.deptAddressName,'无')}
        </td>
    </tr>

     <tr>
        <td style="font-size: 12px;text-align: left">制单人：${that.utils.getCurrentUser().name}</td>
        <td style="font-size: 12px;text-align: left">拣货人：${that.form.picker}</td>
        <td style="font-size: 12px;text-align: left">复核人：</td>
        <td style="font-size: 12px;text-align: left">配送人：</td>
        <td style="font-size: 12px;text-align: left">科室收货人：</td>
    </tr>
</table>
      `,
    }
  },
  //科室退货  汇总打印(按拼命品规批次效期)
  deptReturnSum (that, button){
    let dvParam =  this.getDvParam(that.$refs.childDataView)
    let wrapper = global.$newWrapper()
    wrapper.orderConditions.push({ field: 'matrName', rule: 'asc' })
    dvParam.orderString = JSON.stringify(wrapper.orderConditions)
    //使用列配置
    if (button.printColumns && button.printColumns.length > 0) dvParam.columns = button.printColumns


    let tdLabelStyle = ' style="width: 60px;display: inline-block;" '
    let outerHTML =$(that.$refs.busKeyCode.$el).clone()
    outerHTML.show()

    return {
      setId:'deptReturnSum',
      printerPageWidth: button.printerPageWidth,
      printerPageHeight: button.printerPageHeight,
      printerPageSize: button.printerPageSize,
      //使用列配置
      usePrintSet: true,
      dvParam: dvParam,
      form: that.form,
      tableName: 'dept_return',
      pkName: 'id',
      pkValue: that.form.id,

      //分单字段列表

      //将分单字段显示到副标题

      //分组字段列表，如果分单了，则必须包含分单字段
      groupFields: ['flagInit','matrId','matrSpec','lot', 'expDate'],
      //隐藏字段

      //合计字段
      sumFields: ['skuQty','packageQty','amount'],
      headHtml: `
<table style="border-collapse: collapse; width: 99%; margin-right: auto; table-layout: fixed; ">
    <tr>
        <td  colspan="2">
          <table style="border-collapse: collapse; width: 99%; margin-right: auto;  ">
              <tr>
                  <td colspan="2" style="font-size: 16px;font-weight: bold;padding-bottom: 5px;text-align: center">${global.settings.hospitalName+that.form.warehouseName+'退货单'}</td>
              </tr>
              <tr >
                  <td style="font-size: 12px;text-align: left"><span ${tdLabelStyle}>领用科室：</span>${that.form.deptName}</td>
                   <td style="font-size: 12px;text-align: left"><span  ${tdLabelStyle}>配送仓库：</span>${that.form.warehouseName}</td>
              </tr>
               <tr>
                  <td style="font-size: 12px;text-align: left"><span  ${tdLabelStyle}>申领人：</span></td>
                   <td style="font-size: 12px;text-align: left"><span  ${tdLabelStyle}>备注：</span>${that.strings.defaultIfBlank(that.form.remark,'')}</td>
              </tr>
               <tr>
                  <td style="font-size: 12px;text-align: left"><span  ${tdLabelStyle}>制单时间：</span>${that.form.busDate}</td>
                   <td style="font-size: 12px;text-align: left"><span  ${tdLabelStyle}>出库日期：</span>${global.dates.formatToAnotherPattern(that.form.busDate,'yyyy-MM-dd')}</td>
              </tr>
          </table>
        </td>
        <td>
            ${outerHTML.prop("outerHTML")}
        </td>
    </tr>
</table>
      `,
      footHtml: `
<table style="border-collapse: collapse; width: 99%; margin-right: auto; table-layout: fixed; ">
    <tr>
        <td colspan="3" style="font-size: 12px;text-align: left">第一联财务，第二联仓库，第三联存根联，第四联科室。</td>
         <td colspan="2" style="font-size: 12px;text-align: left">
        收货地址：${global.strings.defaultIfBlank(that.form.deptAddressName,'无')}
        </td>
    </tr>

     <tr>
        <td style="font-size: 12px;text-align: left">制单人：${that.utils.getCurrentUser().name}</td>
        <td style="font-size: 12px;text-align: left">拣货人：${that.form.busUser}</td>
        <td style="font-size: 12px;text-align: left">复核人：</td>
        <td style="font-size: 12px;text-align: left">配送人：</td>
        <td style="font-size: 12px;text-align: left">科室收货人：</td>
    </tr>
</table>
      `,
    }
  },
  //科室调拨  分单明细打印
  printTransfer (that){
    let dvParam =  this.getDvParam(that.$refs.childDataView)
    let wrapper = global.$newWrapper()
    wrapper.orderConditions.push({ field: 'matrName', rule: 'asc' })
    dvParam.orderString = JSON.stringify(wrapper.orderConditions)
    return {
      setId:'printTransfer',
      dvParam: dvParam,
      form: that.form,
      title: global.settings.hospitalName+'调拨单-明细',
      codeLeft: {name: 'busKey', text: '调拨单号',type: 'barcode'},
      codeRight: {name: 'busKey', text: '调拨单号',type: 'qrcode'},


      //合计字段
      sumFields: ['skuQty','amount'],
      head: [
        {name: 'fromWarehouseName', text: '调出仓库',col: 8},
        {name: 'toWarehouseName', text: '调入仓库',col: 8},
        {name: 'busDate', text: '调拨日期',dateFmt: 'yyyy-MM-dd HH:mm:ss',col: 8},
        {name: 'remark', text: '备注', col: 16},
        {name: 'amount', text: '整单金额',col: 8,labelStyle: {fontSize: '14px'},valueStyle: {fontSize: '14px'}},
      ],
      foot: [
        {name: '1', text: '制单人', col: 8,value: that.utils.getCurrentUser().name},
        {name: '2',text: '调拨人', col: 8},
        {name: '3',text: '科室', col: 8},
      ]
    }
  },
  //科室退货  汇总打印(按拼命品规批次效期)
  printTransferSum (that, button){
    let dvParam = this.getDvParam(that.$refs.childDataView)
    let wrapper = global.$newWrapper()
    wrapper.orderConditions.push({ field: 'matrName', rule: 'asc' })
    dvParam.orderString = JSON.stringify(wrapper.orderConditions)

    //使用列配置
    if (button.printColumns && button.printColumns.length > 0) dvParam.columns = button.printColumns

    let tdLabelStyle = ' style="width: 60px;display: inline-block;" '
    let outerHTML =$(that.$refs.busKey.$el).clone()
    outerHTML.show()
    return {
      setId:'printTransferSum',
      dvParam: dvParam,
      form: that.form,
      printerPageWidth: button.printerPageWidth,
      printerPageHeight: button.printerPageHeight,
      printerPageSize: button.printerPageSize,
      //使用列配置
      usePrintSet: true,

      // title: global.settings.hospitalName+'调拨单-汇总',
      // codeLeft: {name: 'busKey', text: '调拨单号',type: 'barcode'},

      //分单字段列表
      // pagebreakFields: ['flagInit'],

      //将分单字段显示到副标题
      // pagebreakFieldAppendTitle:false,

      //分组字段列表，如果分单了，则必须包含分单字段
      groupFields: ['flagInit','matrId','matrSpec','lot', 'expDate'],
      //隐藏字段
      hideFields: ['sn','rfid'],

      //合计字段
      sumFields: ['skuQty','packageQty','amount'],
      headHtml: `
<table style="border-collapse: collapse; width: 99%; margin-right: auto; table-layout: fixed; ">
    <tr>
        <td  colspan="2">
          <table style="border-collapse: collapse; width: 99%; margin-right: auto;  ">
              <tr>
                  <td colspan="2" style="font-size: 16px;font-weight: bold;padding-bottom: 5px;text-align: center">${global.settings.hospitalName+'调拨单'}</td>
              </tr>
              <tr >
                  <td style="font-size: 12px;text-align: left"><span ${tdLabelStyle}>调入仓库：</span>${that.form.toWarehouseName}</td>
                   <td style="font-size: 12px;text-align: left"><span  ${tdLabelStyle}>调出仓库：</span>${that.form.fromWarehouseName}</td>
              </tr>
               <tr>
                  <td style="font-size: 12px;text-align: left"><span  ${tdLabelStyle}>申领人：</span>${that.form.applyUsers}</td>
                   <td style="font-size: 12px;text-align: left"><span  ${tdLabelStyle}>备注：</span>${that.form.remark}</td>
              </tr>
               <tr>
                  <td style="font-size: 12px;text-align: left"><span  ${tdLabelStyle}>制单时间：</span>${that.form.busDate}</td>
                   <td style="font-size: 12px;text-align: left"><span  ${tdLabelStyle}>调拨日期：</span>${global.dates.formatToAnotherPattern(that.form.busDate,'yyyy-MM-dd')}</td>
              </tr>
          </table>
        </td>
        <td>
            ${outerHTML.prop("outerHTML")}
        </td>
    </tr>
</table>
      `,
      footHtml: `
<table style="border-collapse: collapse; width: 99%; margin-right: auto; table-layout: fixed; ">
    <tr>
        <td colspan="3" style="font-size: 12px;text-align: left">第一联财务，第二联仓库，第三联存根联，第四联科室。</td>
        <td colspan="2" style="font-size: 12px;text-align: left">
        收货地址：${global.strings.defaultIfBlank(that.form.deptAddressName,'无')}
        </td>
    </tr>

     <tr>
        <td style="font-size: 12px;text-align: left">制单人：${that.utils.getCurrentUser().name}</td>
        <td style="font-size: 12px;text-align: left">拣货人：${global.strings.defaultIfBlank(that.form.picker,'')}</td>
        <td style="font-size: 12px;text-align: left">复核人：</td>
        <td style="font-size: 12px;text-align: left">配送人：</td>
        <td style="font-size: 12px;text-align: left">科室收货人：</td>
    </tr>
</table>
      `,
    }
  },

  //科室配送  分单明细打印
  distPrintDtl (that){
    let dvParam =  this.getDvParam(that.$refs.childDataViewPick)
    let wrapper = global.$newWrapper()
    wrapper.orderConditions.push({ field: 'matrName', rule: 'asc' })
    dvParam.orderString = JSON.stringify(wrapper.orderConditions)

    return {
      setId:'distPrintDtl',
      dvParam: dvParam,
      form: that.form,
      title: global.settings.hospitalName+'出库单-明细',
      codeLeft: {name: 'busKey', text: '配送单号',type: 'barcode'},
      codeRight: {name: 'busKey', text: '配送单号',type: 'qrcode'},

      tableName: 'wm_dist',
      pkName: 'id',
      pkValue: that.form.id,
      //分单字段列表
      pagebreakFields: ['flagInit'],
      pagebreakFieldAppendTitle:true,

      //合计字段
      sumFields: ['packageQty','amount'],
      head: [
        {name: 'warehouseName', text: '配送仓库',col: 6},
        {name: 'busDate', text: '配送日期',dateFmt: 'yyyy-MM-dd',col: 6},
        {name: 'deptName', text: '配送至',col: 12,labelStyle: {fontSize: '14px'},valueStyle: {fontSize: '14px'}},
        {name: 'amount', text: '整单金额',col: 8,labelStyle: {fontSize: '14px'},valueStyle: {fontSize: '14px'}},
        {name: 'remark', text: '备注', col: 16},
      ],
      foot: [
        {name: '1', text: '制单人', col: 8,value: that.utils.getCurrentUser().name},
        {name: 'picker',text: '拣货人', col: 8},
        {name: '2',text: '配送人', col: 8},
        {name: '3',text: '领用人', col: 8},
      ]
    }
  },

  //科室配送  分单汇总打印(按拼命品规批次效期)
  printSpecialSum (that){
    let dvParam =  this.getDvParam(that.$refs.childDataViewPick)
    let wrapper = global.$newWrapper()
    wrapper.orderConditions.push({ field: 'matrName', rule: 'asc' })
    dvParam.orderString = JSON.stringify(wrapper.orderConditions)
    return {
      setId:'printSpecialSum',
      dvParam: dvParam,
      form: that.form,
      title: global.settings.hospitalName+'科室出库单(专购品)-汇总',
      codeLeft: {name: 'busKey', text: '配送单号',type: 'barcode',labelStyle: {fontSize: '15px'},valueStyle: {fontSize: '15px'}},
      codeRight: {name: 'busKey', text: '配送单号',type: 'qrcode'},

      tableName: 'wm_dist',
      pkName: 'id',
      pkValue: that.form.id,
      //分单字段列表
      pagebreakFields: ['flagInit'],

      //将分单字段显示到副标题
      pagebreakFieldAppendTitle:true,

      //分组字段列表，如果分单了，则必须包含分单字段
      groupFields: ['flagInit','matrId','matrSpec','lot', 'expDate'],
      //隐藏字段
      hideFields: ['sn','rfid'],

      //合计字段
      sumFields: ['skuQty','amount'],
      head: [
        {name: 'warehouseName', text: '配送仓库',col: 6},
        {name: 'busDate', text: '配送日期',dateFmt: 'yyyy-MM-dd',col: 6},
        {name: 'deptName', text: '配送至',col: 12,labelStyle: {fontSize: '14px'},valueStyle: {fontSize: '14px'}},
        {name: 'amount', text: '整单金额',col: 8,labelStyle: {fontSize: '14px'},valueStyle: {fontSize: '14px'}},
        {name: 'remark', text: '备注', col: 16},
      ],
      foot: [
        {name: '1', text: '制单人', col: 8,value: that.utils.getCurrentUser().name},
        {name: 'picker',text: '拣货人', col: 8},
        {name: '2',text: '配送人', col: 8},
        {name: '3',text: '领用人', col: 8},
      ]
    }
  },
  //
  printDemand (viewForm){
    let dvParam =  this.getDvParam(viewForm.$refs.childDataView)
    let wrapper = global.$newWrapper()
    wrapper.orderConditions.push({ field: 'matrName', rule: 'asc' })
    dvParam.orderString = JSON.stringify(wrapper.orderConditions)

    return {
      setId:'printDemand',
      dvParam: dvParam,
      form: viewForm.form,
      title: global.settings.hospitalName+'配送需求',
      codeLeft: {name: 'busKey', text: '配送单号',type: 'barcode'},
      head: [
        {name: 'busDate', text: '配送日期',dateFmt: 'yyyy-MM-dd',col: 8},
        {name: 'deptName', text: '配送至',col: 16,labelStyle: {fontSize: '15px'},valueStyle: {fontSize: '15px'}},
        {name: 'warehouseName', text: '配送仓库',col: 8},
        {name: 'remark', text: '备注', col: 16},
      ],
      foot: [
        {name: '1', text: '设备科审核', col: 6},
        {name: '2',text: '库管', col: 6},
        {name: '3',text: '科室负责人', col: 6},
      ]
    }
  },
  //准入审批行打印
  admPrintDtl (that, rowData){
    console.log('rowData', rowData)
    let baseApi = location.origin+'/api'
    let useReasonNamesArr = rowData.useReasonNames ? rowData.useReasonNames.split(','): []
    let useReasonNameHtml = useReasonNamesArr.join('<br>')
    if (rowData.useReasonCodes.includes('other')) useReasonNameHtml +=  `<span style="'padding-left: 11px'"> ${rowData.useReasonOther}</span>`


    let signPath1 = rowData.signPath1
    let signPath2 = rowData.signPath2

    let param = {
      setId:'admPrintDtl',
      onlyForm: true,
      dvParam: {},
      form: rowData,
      title: `
          <img src="${global.settings.admPrintTop}" style="height: 55px"><br>
         新品规医用耗材申请
      `,
      head: [


        {name: 'busKey', text: '审批单/日期',col: 12, value: that.form.busKey+'/'+ global.dates.formatToAnotherPattern(that.form.busDate, 'yyyy-MM-dd')},
        {name: 'busKey', text: '申请单/日期',col: 12, value: rowData.applyBusKey+'/'+ global.dates.formatToAnotherPattern(rowData.applyBusDate, 'yyyy-MM-dd')},


        {name: 'field3', text: '汇总人/科室',col: 12,value: that.form.busUser+'/' +that.form.deptName},
        {name: 'field4', text: '申请人/科室',col: 12,value: rowData.applyBusUser+'/' +rowData.applyDeptName},

        {name: 'matrName', text: '',col: 12},
        {name: 'matrSpec', text: '',col: 12},

        {name: 'mfgName', text: '厂商',col: 24},

        {name: 'sunpurchaseCode', text: '阳采代码',col:12},

        {name: 'flagRecordPurchase', text: '备案采购',col: 12, value: rowData.flagRecordPurchase == 1 ? '是' : '否'},


        {name: 'advantageRemark', text: '新品优势阐述',col: 24},

        {name: 'num1', text: '在院类似品种数量',col: 12},
        {name: 'eliminateMatrName', text: '欲淘汰品牌',col: 12},

        {name: 'useScopeNames', text: '使用范围',col: 24},

        {name: 'qtyYear', text: '预计年用量',col: 24},

        {name: 'useNames', text: '用途',col: 24},

        {name: 'useReasonNames', text: '申购理由',col: 24, valueStyle: {maxWidth: '70%', textAlign: 'left'},
          value: `${useReasonNameHtml}`},


        {name: 'field22', text: '签字',col: 24,value: `
            <table>
                <tr>
                    <td>科主任</td>
                    <td><img src="${baseApi+signPath2}" style="height: 30px"></td>
                     <td>医疗副主任</td>
                    <td></td>
                </tr>
                <tr>
                    <td>教学副主任</td>
                    <td></td>
                     <td>科研副主任</td>
                    <td></td>
                </tr>
                <tr>
                    <td>科室核心小组成员</td>
                    <td colspan="3"><img src="${baseApi+signPath1}" style="height: 30px"></td>
                </tr>
            </table>
        `},


        {name: 'field23', text: '审核',col: 24,value: `
            <table>
                <tr>
                    <td>设备处意见</td>
                    <td></td>
                </tr>
                <tr>
                     <td>院领导意见</td>
                    <td></td>
                </tr>
            </table>
        `},

        {name: 'field24', text: '备注',col: 24, valueStyle: {maxWidth: '70%', textAlign: 'left'},
          value: global.settings.admPrintRemark },

        //右下角脚注
        {name: 'field25', text: '',col: 24, valueStyle: {maxWidth: '70%', textAlign: 'right', width: '100%'},
          value:global.settings.admPrintDtlRight},
      ]
    }


    let labelStyle = {display: 'inline-block', float: 'none'}
    let colSum = 0
    param.head.forEach(ob => {
      let colStyle = {border: '1px solid #606266'}
      //宽度: 百分比
      let width = ob.col/24*100 - 2  +'%'
      colStyle.minWidth = width
      colStyle.maxWidth = width
      colStyle.width = width
      colSum+=ob.col
      if (colSum >= 24 && ob.col != 24) {
        colStyle.borderLeft = 'none'
        colSum = 0
      }
      if (ob.col == 24) {
        let width = ob.col/24*100 - 4  +'%'
        colStyle.minWidth = width
        colStyle.maxWidth = width
        colStyle.width = width
        colSum = 0
      }

      ob.colStyle = colStyle
    })

    return param
  },

  //准入审批 表头打印
  admPrintMain (viewForm){

    if (viewForm.$refs.childDataViewAuditItemResult.tablePage.totalResult < 1) {
      viewForm.$message.warning('没有符合条件的报价结果，不需要打印')
      return
    }

    let param = {
      setId:'admPrintMain',
      dvParam: this.getDvParam(viewForm.$refs.childDataViewAuditItemResult),
      form: viewForm.form,
      title: global.settings.hospitalName+'新进申请表汇总',
      head: [
        {name: 'busKey', text: '审批单',col: 8},
        {name: 'busDate', text: '审批日期',dateFmt: 'yyyy-MM-dd',col: 8}
      ],
      foot: [
        {name: '1', text: '院长', col: 6},
        {name: '2',text: '主管院长', col: 6},
        {name: '3',text: '设备处处长', col: 6},
        {name: '4',text: '耗材管理科科长', col: 6},
        {name: '5',text: '制表人', col: 6},
      ]
    }
    param.dvParam.listEntry = 'adm/matr_audit_item/pageForAuditSelectWitchMatrAndResult'
    param.dvParam.queryString = viewForm.$refs.childDataViewAuditItem.generateQuery()
    return  param
  },

  //供应商出库  分单汇总打印(按品名品规批次效期)
  outOrderPrintSum (that){

    return {
      setId:'outOrderPrintSum',
      dvParam: this.getDvParam(that.$refs.childDataView),
      form: that.form,
      title: global.settings.hospitalName+'供应商出库单-汇总',
      codeLeft: {name: 'busKey', text: '出库单号',type: 'barcode'},

      tableName: 'wm_work_order',
      //分单字段列表
      pagebreakFields: ['flagInit'],

      //将分单字段显示到副标题
      pagebreakFieldAppendTitle:false,

      //分组字段列表，如果分单了，则必须包含分单字段
      groupFields: ['flagInit','matrId','matrSpec','lot', 'expDate'],
      //隐藏字段
      hideFields: ['sn','rfid'],

      //合计字段
      sumFields: ['skuQty','amount'],
      head: [
        {name: 'busKey', text: '出库单号',col: 8},
        {name: 'warehouseName', text: '出库仓库',col: 8},
        {name: 'busDate', text: '出库日期',dateFmt: 'yyyy-MM-dd',col: 8},
        {name: 'supplierName', text: '供应商',col: 16},
        {name: 'amount', text: '整单金额',col: 8,labelStyle: {fontSize: '14px'},valueStyle: {fontSize: '14px'}},
        { name: 'remark', text: '备注', col: 24 }
      ],
      foot: [
        {name: '1', text: '制单人', col: 8,value: that.utils.getCurrentUser().name},
        {name: '2',text: '退货人', col: 6},
        { name: '3', text: '供应商', col: 6 }
      ]
    }
  },
  //包入库
  inOrderPackage(viewForm, packName) {
    let wrapper = viewForm.$newWrapper().eq('workOrderId', viewForm.form.id).eq('matr_type', '0')
    let columnNew = JSON.parse(JSON.stringify(viewForm.$refs.childDataView.propChildColumns))

    let param = {
      setId:'inOrderPackage',
      dvParam: {
        //后台查询接口，若最后一个路径包含page，则替换成list
        listEntry: '/wm/work_order_item/list',
        //当前对象字段列表
        columns: columnNew,
        //查询条件
        queryString: JSON.stringify(wrapper.queryConditions),
        //排序条件
        orderString: null,
        //当前对象数据总计
        totalResult: viewForm.$refs.childDataView.tablePage.total
      },
      form: viewForm.form,
      title: '跟台包入库单',
      codeLeft: {name: 'busKey', text: '入库单号',type: 'barcode'},
      codeRight: {name: 'busKey', text: '入库单号',type: 'qrcode'},
      head: [
        {name: 'supplierName', text: '供应商',col: 16},
        {name: 'warehouseName', text: '入库仓库',col: 8},
        {name: 'busDate', text: '入库日期',dateFmt: 'yyyy-MM-dd'},
        {name: 'busKey', text: '入库单号'},
        { name: 'amount', text: '金额' },
        { name: 'packName', text: '跟台包名称', value: packName }
      ],
      foot: [
        {name: '1', text: '制单人', col: 8,value: viewForm.utils.getCurrentUser().name},
        { name: '2', text: '保管人', col: 8 }
      ]
    }
    return param
  },
  //采购订单-二维码
  purchasePrintQr (viewForm){
    return {
      setId:'inOrderInit',
      dvParam: this.getDvParam(viewForm.$refs.childDataView),
      form: viewForm.form,
      title: '采购订单',
      codeLeft: {name: 'busKey', text: '采购单号',type: 'barcode'},
      flagCodeInfo: true,
      barCodeInfo: viewForm.itemData.items,
      head: [
        {name: 'supplierName', text: '供应商',col: 16},
        {name: 'warehouseName', text: '入库仓库',col: 8},
        {name: 'busDate', text: '入库日期',dateFmt: 'yyyy-MM-dd'},
        {name: 'busKey', text: '入库单号'},
        {name: 'amount', text: '金额'}
      ]
    }
  },
  //采购订单-普通
  purchasePrint (viewForm){
    return {
      setId:'inOrderInit',
      dvParam: this.getDvParam(viewForm.$refs.childDataView),
      form: viewForm.form,
      title: '采购订单',
      codeLeft: {name: 'busKey', text: '采购单号',type: 'barcode'},
      flagCodeInfo: true,
      head: [
        {name: 'supplierName', text: '供应商',col: 16},
        {name: 'warehouseName', text: '入库仓库',col: 8},
        {name: 'busDate', text: '入库日期',dateFmt: 'yyyy-MM-dd'},
        {name: 'busKey', text: '入库单号'},
        {name: 'amount', text: '金额'}
      ]
}
  },


}

export default printSet
